#include "main.h"
uint8_t HostID[4];

uint16_t CalcCRC1(uint8_t *ptr,uint8_t Length,uint16_t verify)
{
     uint8_t i,CrcData;
     uint16_t CheckSum = 0xFFFF;
     while (Length --)
     {
        CrcData = * (ptr ++);
        for (i=0u;i<8u;i++)
        {
           if (((CheckSum & 0x8000) >> 8) ^ (CrcData & 0x80))
              CheckSum = (CheckSum << 1) ^ verify;
           else
              CheckSum = (CheckSum << 1);
           CrcData <<= 1;
        }   
     }
		 return CheckSum;
     //CrcHi = CheckSum >> 8;
     //CrcLo = CheckSum;
}   
void ReadMcuID(void)
{
	uint8_t i;
	uint8_t HostNum[10];
	uint16_t ho,lo;
	for(i=0;i<10;i++)
	{
	   HostNum[i]= *((volatile uint8_t*)(IDBase+i));
	}
	ho=CalcCRC1(HostNum,10,0x8005);
	lo=CalcCRC1(HostNum,10,0x8001);
	HostID[0]=ho>>8;
	HostID[1]=ho;
	HostID[2]=lo>>8;
	HostID[3]=lo;
	SysMem.Address.Module.Addr[0]=HostID[0];
	SysMem.Address.Module.Addr[1]=HostID[1];
	SysMem.Address.Module.Addr[2]=HostID[2];
	SysMem.Address.Module.Addr[3]=HostID[3];
}
